package com.itheima.d4_homework;

/**
 * 啤酒问题
 */
public class Demo2 {
    private static int bottleCaps = 0;
    private static int emptyBottles = 0;
    private static int totalBeer = 0;

    public static void main(String[] args) {
        int money = 10;
        int initialBeer = money / 2;
        System.out.println("开始喝啤酒...");
        drinkBeer(initialBeer);
        exchengeBeer();
        System.out.println("总共喝了："+totalBeer+ "瓶啤酒");



    }
    public static void drinkBeer(int count){
        //判断count是否大于0
        if(count <= 0){
            return;
        }else{
            bottleCaps += count;
            emptyBottles += count;
            totalBeer += count;
        }
    }
    public static void exchengeBeer(){
        int newBeer = 0;
        //4个瓶盖换1瓶啤酒
        int capExchange = bottleCaps / 4;
        bottleCaps %= 4;//剩余数量

        //2个空瓶换1瓶啤酒
        int bottleExchange = emptyBottles / 2;
        emptyBottles %= 2; //剩余空瓶

        newBeer = capExchange + bottleExchange;
        //判断 如果新兑换的啤酒数量大于0 还可以继续兑换
        if(newBeer > 0){
            drinkBeer(newBeer);
            exchengeBeer();//继续兑换
        }
    }
}

